#include "plant_1DSOS_RDM_v4.h"
// --------------------------------------------------
plant_1DSOS_RDM::plant_1DSOS_RDM(double idt,int iDim,int iL,int iMode, double iE_D,double iE_S,double iE_N)
{
  cout << "plant_1DSOS_RDM::plant_1DSOS_RDM()\n";
  // Options ------------------------------------------------------------------
  Dim = iDim;
  if(Dim == 1){
    Lx = iL;
    Ly = 1;
    N_CL = 3;
  }
  else{
    Lx = iL;
    Ly = iL;
    N_CL = 5;
  }

  mode = iMode;
  assert(2*iMode<=iL);
  E_D = iE_D;
  E_S = iE_S;
  E_N = iE_N;
  lattice = new MCArray(Lx);
  cout << "MCArray created successfully\n";
  //	cout << "block::input_dim[]=" << block::input_dim[0] << ", " << block::input_dim[1] << "\n";
  // States -------------------------------------------------------------------
  // lattice = new int*[Ly];
  //	lattice = new MCArray(Lx);
  lattice_stat =  new int*[Ly];
  xcov_val = new double[Lx];
  for(int i=0;i<Ly;i++){
    // lattice[i] = new int[Lx];
    lattice_stat[i] = new int[Lx];
  }
  p_migr = new double[Ly];
  p_desorp = new double[Ly];
  cout << "plant_1DSOS_RDM():line 52\n";
  // Initialize random number generator ---------------------------------------
	gsl_rng_env_setup();
	gsl_T = gsl_rng_default;
	gsl_r = gsl_rng_alloc(gsl_T);
	gsl_rng_set(gsl_r,time_seed());

	double SQRT_TWO = sqrt(2.0);
	double SQRT_PI = sqrt(pi);
	reset();
	cout << "plant_1DSOS_RDM():line 62\n";

	// Save a log --------------------------------------------------------------
	ofstream flog("plant_1DSOS_RDM_v2.log");
	flog << "Dim     = " << Dim << "\n";
	flog << "Lx      = " << Lx << "\n";
	flog << "Ly      = " << Ly << "\n";
	flog << "E_D     = " << E_D << "\n";
	flog << "E_S     = " << E_S << "\n";
	flog << "E_N     = " << E_N << "\n";
	flog.close();
	cout << "END OF plant_1DSOS_RDM::plant_1DSOS_RDM()\n";
}
// --------------------------------------------------
plant_1DSOS_RDM::~plant_1DSOS_RDM()
{
  cout << "Begin of ~plant_1DSOS_RDM()\n";
	int i;
	cout << "before delete lattice\n";
	delete lattice;
	cout << "deleted lattice\n";
	for(i=0;i<Ly;i++)
	{
	  // delete []lattice[i];
		delete []lattice_stat[i];
	}
	//delete []lattice;
	delete []lattice_stat;
	delete []xcov_val;
	delete []p_migr;
	delete []p_desorp;
	gsl_rng_free(gsl_r);
	cout << "End of ~plant_1DSOS_RDM()\n";
}
// --------------------------------------------------
/*void plant_1DSOS_RDM::reset()
{
	block::time = 0.0;

	// Inputs
	T = 0;
	W = 0;

	// States
	int x,y;
	/*for(y=0;y<Ly;y++){
		for(x=0;x<Lx;x++){
			lattice[y][x] = 0;
		}
	}*/
	for(x=0;x<Lx;x++){
	  //cout << "lattice->SetElement(" << x << ",0.0)\n";
	  lattice->SetElement(x,0.0);
	}
	for(y=0;y<Ly;y++){
		for(x=0;x<Lx;x++){
			init_local_stat(x,y);
		}
	}

	// Outputs
	h  = 0.0;
	r2 = 0.0;
	m2 = 0.0;
	a  = Lx;
	cout << "END of plant_1DSOS_RDM::reset()\n";
}*/

